<template>
  <div>
    <el-cascader
      :value="value"
      :options="options"
      clearable
      :props="{value:'id',label:'name'}"
      @change="cascaderChange"
    ></el-cascader>
  </div>
</template>

<script>
import { companyDepartmentRequest } from '@/api/department'
import { transformListToTree } from '@/utils/index'
export default {
  props: ['value'],
  data() {
    return {
      options: []
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    async getDepartmentList() {
      const res = await companyDepartmentRequest()
      this.options = transformListToTree(res.data, 0)
    },
    // 级联选择器事件方法
    cascaderChange(val) {
      if (val.length > 0) { this.$emit('input', val[val.length - 1]) } else { this.$emit('input', null) }
    }
  }
}
</script>

<style>

</style>
